package com.isoft.dao.flightUpdate;

import com.isoft.entity.flightUpdate.FlightUpdateVo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author LiuGaoMing
 * @version 1.0
 * @description:
 * @date 2024/7/1 0:20
 */
@Mapper
public interface FlightVoDao {
    // 查询所有（分页）
    @Select("SELECT * FROM DFME_AIRL_HISTORY LIMIT #{offset}, #{pageSize}")
    List<FlightUpdateVo> getFlightAllVoPaged(@Param("offset") int offset, @Param("pageSize") int pageSize);

    // 获取总记录数
    @Select("SELECT COUNT(*) FROM DFME_AIRL_HISTORY")
    Long getTotalFlightRecords();

//    根据NAPCD1,NAPCD2,NAPCD3模糊查询动态sql
    @Select("<script>" +
            "SELECT * FROM DFME_AIRL_HISTORY " +
            "<where> " +
            "<if test='NAPCD1 != null and NAPCD1 != \"\"'> " +
            "AND NAPCD1 LIKE CONCAT('%', #{NAPCD1}, '%') " +
            "</if> " +
            "<if test='NAPCD2 != null and NAPCD2 != \"\"'> " +
            "AND NAPCD2 LIKE CONCAT('%', #{NAPCD2}, '%') " +
            "</if> " +
            "<if test='NAPCD3 != null and NAPCD3 != \"\"'> " +
            "AND NAPCD3 LIKE CONCAT('%', #{NAPCD3}, '%') " +
            "</if> " +
            "</where> " +
            "LIMIT #{offset}, #{pageSize} " +
            "</script>")
    List<FlightUpdateVo> getFlightVoByNAPCDsPaged(
            @Param("NAPCD1") String NAPCD1,
            @Param("NAPCD2") String NAPCD2,
            @Param("NAPCD3") String NAPCD3,
            @Param("offset") int offset,
            @Param("pageSize") int pageSize);
    // 获取符合条件的总记录数

    @Select("<script> " +
            "SELECT COUNT(*) FROM DFME_AIRL_HISTORY " +
            "<where> " +
            "<if test='NAPCD1 != null and NAPCD1 != \"\"'> " +
            "AND NAPCD1 LIKE CONCAT('%', #{NAPCD1}, '%') " +
            "</if> " +
            "<if test='NAPCD2 != null and NAPCD2 != \"\"'> " +
            "AND NAPCD2 LIKE CONCAT('%', #{NAPCD2}, '%') " +
            "</if> " +
            "<if test='NAPCD3 != null and NAPCD3 != \"\"'> " +
            "AND NAPCD3 LIKE CONCAT('%', #{NAPCD3}, '%') " +
            "</if> " +
            "</where> " +
            "</script> ")
    Long getTotalFlightRecordsByNAPCDs(
            @Param("NAPCD1") String NAPCD1,
            @Param("NAPCD2") String NAPCD2,
            @Param("NAPCD3") String NAPCD3);
//    插入数据
    @Insert("insert into DFME_AIRL_HISTORY(META_ID,APAT,APNO1,APNO2,APNO3,APCD1,APCD2,APCD3,NAPCD1,NAPCD2,NAPCD3,STATU) values(#{METAID},#{APAT},#{APNO1},#{APNO2},#{APNO3},#{APCD1},#{APCD2},#{APCD3},#{NAPCD1},#{NAPCD2},#{NAPCD3},#{STATU})")
    public Boolean insertFlightVo(FlightUpdateVo flightUpdateVo);

//    通过STATU和META_ID查找DFME_AIRL_HISROTY中待审核的APCD1，APCD2，APCD3赋值给vo
//    getAPCD
    @Select("SELECT * FROM DFME_AIRL_HISTORY WHERE STATU=#{STATU} AND META_ID = #{METAID} ")
    public List<FlightUpdateVo> getAPCD(String STATU,Integer METAID);
}
